<template>
	<view>
		<view v-if="list.length == 0" class='empty'>--暂无数据--</view>
		<uni-list v-else>
			<uni-list-item :title="article.title" :note="article.updateTime" link v-for="article in list" :key='article.id'
				@click="goView(article)">
			</uni-list-item>
			<uni-load-more :status="status" @clickLoadMore="getArticleList(++page)"></uni-load-more>
		</uni-list>
	</view>
</template>

<script>
	import {
		getArticleList
	} from '@/api/articleList/index.js'
	export default {
		data() {
			return {
				list: [],
				page: 1,
				pageSize: 20,
				count: 0,
				status: 'more',
				username: uni.getStorageSync('user').username
			}
		},
		onShow() {
			console.log(uni.getStorageSync('user'))
			this.list = []
			this.getArticleList(this.page)
		},
		// 下拉刷新
		// onPullDownRefresh() {
		// 	this.page = 1
		// 	this.list = []
		// 	this.getArticleList(this.page).then(() => {
		// 		uni.stopPullDownRefresh();
		// 	})
		// },
		onNavigationBarButtonTap(e) { //加号
			uni.navigateTo({
				url: '/pages/document/document'
			})
		},
		methods: {
			getArticleList(page) {
				this.status = 'loading'
				const postData = {
					page,
					limit: this.pageSize,
					username: this.username
				}
				return getArticleList(postData).then(res => {
					const data = res.data
					const list = data.list || []
					this.list = [...this.list, ...list]
					this.count = data.count

					if (this.list.length >= this.count) {
						this.status = 'nomore'
					} else {
						this.status = 'more'
					}
				})
			},
			goView(article) {
				uni.navigateTo({
					url: `/pages/document/document?type=view&id=${article.uuid}`
				})
			}
		}
	}
</script>

<style scoped>
	.main {
		/* position: relative; */
	}

	.empty {
		position: absolute;
		top: 40%;
		left: 50%;
		transform: translate(-50%, -50%);
		color: #ccc;
	}
	/deep/.uni-list-item__content-title{
		font-size: 16px;
	}
	/deep/.uni-list--border:after{
		height: 0;
	}
	/deep/.uni-list-item{
		box-shadow: 0px 2px 6px 0px rgb(0 0 0 /30%);
		margin: 10px 8px;
		border-radius: 8px;
	}
	/deep/.uni-list--border-bottom{
		height: 0;
	}
</style>
